//
// Created by Administrator on 2023/8/14.
//
#include<vector>
#include <iostream>
#include <algorithm>

using namespace std;

class Solution {
public:
    int minimumCost(vector<int> &cost) {
        // 3个一位，只能选择买贵的两个，送便宜的那个
        sort(cost.begin(), cost.end(), greater<>());
        int ans = 0, n = cost.size();
        for (int i = 0; i < n; i += 3) {
            // 只剩一个了
            if (i == n - 1)
                ans += cost[i];
            else {
                ans += cost[i];
                ans += cost[i + 1];
            }
        }
        return ans;
    }
};


int main() {
    vector<int> cost{6, 5, 7, 9, 2, 2};
    Solution s;
    cout << s.minimumCost(cost) << endl;
    return 0;
}